<?php
function get_default_lng_id(){		
	if(cookie('home_language')) {
		$language_id = cookie('home_language');
	}else{
		$language_id = C('DEFAULT_LANG',null,1);
	}
	return $language_id;
}

/**
 * 获取当前语言的指定字段的值
 * @param $field  -	要获取的字段名
 * @return string - 字段的值
 */
function get_lang($field='code'){
	$map=array(
		'status'			=>	1,
		'language_id'		=>	get_default_lng_id()
		);
		$language=M('Language')->where($map)->field($field)->find();
	return $language[$field];
}

function get_languages(){
	$map=array(
		'status'	=>	1
		);
	$languages=M('Language')->where($map)->select();
	return $languages;
}

/**
 * 
 */
function get_setting($key){
	$setting	=	M('Setting')->where(array('key'=>$key))->find();
	$return='';
	if($setting){
		$value=json_decode($setting['value'],true);
		$v=$value[get_default_lng_id()];
		switch ($setting['type']) {
			case '2':
				$return=C('HTTP_IMAGE') . 'images/' . $v;
				break;
			case '3':
				$return=htmlspecialchars_decode($v);
				break;		
			default:
				$return=$v;
				break;
		}
	}
	return $return;
}